﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Collections.Generic;
using System.Windows.Threading;
using Fulcrum.DispatcherProxies;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.DispatcherProxies
{
    [TestClass]
    public class DispatcherProxyGenerationPolicyTests
    {
        public DispatcherProxyGenerationPolicyTests()
        {
            // nothing
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyAreParametersSupportedNoParameters()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("NoParameterMethod");
            var result = DispatcherProxyGenerationPolicy.AreParametersSupported(method.GetParameters());

            Assert.IsTrue(result);
        }

        public void NoParameterMethod()
        {
            throw new NotImplementedException();
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyAreParametersSupportedGoodParameters()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("GoodParametersMethod");
            var result = DispatcherProxyGenerationPolicy.AreParametersSupported(method.GetParameters());

            Assert.IsTrue(result);
        }

        public void GoodParametersMethod(int param1, string param2, ICollection<List<bool>> param3)
        {
            throw new NotImplementedException();
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyAreParametersSupportedOutParameters()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("OutParameterMethod");
            var result = DispatcherProxyGenerationPolicy.AreParametersSupported(method.GetParameters());

            Assert.IsFalse(result);
        }

        public void OutParameterMethod(out int param1)
        {
            throw new NotImplementedException();
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyAreParametersSupportedRefParameters()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("RefParameterMethod");
            var result = DispatcherProxyGenerationPolicy.AreParametersSupported(method.GetParameters());

            Assert.IsFalse(result);
        }

        public void RefParameterMethod(ref int param1)
        {
            throw new NotImplementedException();
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyIsProxyableTypeObject()
        {
            var result = DispatcherProxyGenerationPolicy.IsProxyableType(typeof(Object));

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyIsProxyableTypeDispatcherObject()
        {
            var result = DispatcherProxyGenerationPolicy.IsProxyableType(typeof(DispatcherObject));

            Assert.IsTrue(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyIsProxyableTypePublicType()
        {
            var result = DispatcherProxyGenerationPolicy.IsProxyableType(typeof(DispatcherProxyGenerationPolicyTests));

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyIsProxyableTypePublicDispatcherObjectDecendant()
        {
            var result = DispatcherProxyGenerationPolicy.IsProxyableType(typeof(PublicDispatcherObjectDecendant));

            Assert.IsTrue(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyIsProxyableTypePublicNestedDispatcherObjectDecendant()
        {
            var result = DispatcherProxyGenerationPolicy.IsProxyableType(typeof(PublicNestedDispatcherObjectDecendant));

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationPolicyIsProxyableTypePrivateDispatcherObjectDecendant()
        {
            var result = DispatcherProxyGenerationPolicy.IsProxyableType(typeof(PrivateDispatcherObjectDecendant));

            Assert.IsFalse(result);
        }

        public class PublicNestedDispatcherObjectDecendant : DispatcherObject
        {
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationProxyIsSupportedMethodGetType()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("GetType");
            var result = DispatcherProxyGenerationPolicy.IsSupportedMethod(method);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationProxyIsSupportedMethodInvalidParameterMethod()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("OutParameterMethod");
            var result = DispatcherProxyGenerationPolicy.IsSupportedMethod(method);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationProxyIsSupportedMethodValidMethod()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("TestDispatcherProxyGenerationProxyIsSupportedMethodValidMethod");
            var result = DispatcherProxyGenerationPolicy.IsSupportedMethod(method);

            Assert.IsTrue(result);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationProxyIsSupportedMethodSpecialName()
        {
            var method = typeof(DispatcherProxyGenerationPolicyTests).GetMethod("get_Property");
            var result = DispatcherProxyGenerationPolicy.IsSupportedMethod(method);

            Assert.IsFalse(result);
        }

        public int Property
        {
            get
            {
                throw new NotImplementedException();
            }
        }

    }

    public class PublicDispatcherObjectDecendant : DispatcherObject
    {
    }

    class PrivateDispatcherObjectDecendant : DispatcherObject
    {
    }

}
